package calm.museum;

import java.util.ArrayList;

import jenamuseum.annotation.Annotation;
import jenamuseum.annotation.AnnotationBase;
import jenamuseum.annotation.AnnotationVideo;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
/**
* This class allow to create custom  list, with customize rendering 
* for annotation. It extends the basic ArrayAdapter class used to render
* list of objects using the toString method. To customize the way 
* annotation are rendering in list, one shall modify the getView function
**/
public class AnnotationArrayAdapter extends ArrayAdapter<AnnotationBase>{
	private ArrayList<AnnotationBase> items;
	private Context mContext;
	private int[] colors = new int[] { 0x30FFFFFF, 0x300000FF };
	private LayoutInflater inflater;


	public AnnotationArrayAdapter(Context context, int textViewResourceId,
			ArrayList<AnnotationBase> items) {
		super(context, textViewResourceId, items);
		this.items=items;
		mContext = context;
		inflater= LayoutInflater.from(mContext);
	}
	
	public View getView(int position, View convertView, ViewGroup parent)
	{
		 if (items.get(position) instanceof Annotation)
		 {
			 Log.w("Annotation", "OK c'est une annotation" + ((Annotation)items.get(position)).getAuthor());
		 }
		 if (items.get(position) instanceof AnnotationVideo)
		 {
			 Log.w("Annotation", "OK c'est une annotation Vidéo" + ((AnnotationVideo)items.get(position)).getUrl());
		 }

		 View row=inflater.inflate(R.layout.note_row_layout, parent, false);
		 TextView noteTitle=(TextView)row.findViewById(R.id.noteTitle);
		 TextView noteAuthorDate=(TextView)row.findViewById(R.id.noteAuthorDate);
		 noteTitle.setText(items.get(position).getTitle());
		 noteAuthorDate.setText(items.get(position).getAuthor());
		 int colorPos = position % colors.length;
		 noteAuthorDate.setBackgroundColor(colors[colorPos]);
		 noteTitle.setBackgroundColor(colors[colorPos]);

		 return row;
		}
}
